<template>
  <div>
    <!-- 表格 -->
    <el-table :data="dataList" style="width:100%" border="">
      <el-table-column type="index" label="序号" align="center" width="80px" />
      <el-table-column prop="skuName" label="名称" width="width" />
      <el-table-column prop="skuDesc" label="描述" width="width" />
      <el-table-column prop="prop" label="默认图片" width="110px">
        <template slot-scope="{row}">
          <img :src="row.skuDefaultImg" style="width:80px;height:80px" alt="">
        </template>
      </el-table-column>
      <el-table-column prop="weight" label="重量" width="80px" />
      <el-table-column prop="price" label="价格" width="110px" />
      <el-table-column prop="prop" label="操作" width="width">
        <template slot-scope="{row}">
          <el-button v-if="row.isSale==0" type="success" size="mini" icon="el-icon-top" @click="sale(row)" />
          <el-button v-else type="info" size="mini" icon="el-icon-bottom" @click="cancel(row)" />
          <el-button type="primary" size="mini" icon="el-icon-edit" @click="edit" />
          <el-button type="info" size="mini" icon="el-icon-info" @click="getSkuInfo(row)" />
          <el-button type="danger" size="mini" icon="el-icon-delete" />
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <!-- @size-change="handleSizeChange"
      @current-change="handleCurrentChange" -->
    <el-pagination style="text-align: center" :current-page="page" :page-sizes="[3, 5, 10]" :page-size="limit" layout="prev, pager, next, jumper,->, sizes,total" :total="total" @size-change="handleSizeChange" @current-change="getList" />
    <!-- 抽屉 -->
    <el-drawer size="50%" :visible.sync="show">
      <el-row>
        <el-col :span="5">名称</el-col>
        <el-col :span="16">{{ skuInfo.skuName }}</el-col>
      </el-row>
      <el-row>
        <el-col :span="5">描述</el-col>
        <el-col :span="16">{{ skuInfo.skuDesc }}</el-col>
      </el-row>
      <el-row>
        <el-col :span="5">价格</el-col>
        <el-col :span="16">{{ skuInfo.price }}元</el-col>
      </el-row>
      <el-row>
        <el-col :span="5">平台属性</el-col>
        <el-col :span="16">
          <template>
            <el-tag v-for="attr in skuInfo.skuAttrValueList" :key="attr.id" style="margin-right:10px" type="success">{{ attr.attrId }}--{{ attr.valueId }}</el-tag>
          </template>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="5">商品图片</el-col>
        <el-col :span="16">
          <el-carousel height="150px">
            <el-carousel-item v-for="item in skuInfo.skuImageList" :key="item.id">
              <img style="height:150px" :src="item.imgUrl">
            </el-carousel-item>
          </el-carousel>
        </el-col>
      </el-row>
    </el-drawer>
  </div>
</template>

<script>
export default {
  name: 'Sku',
  data() {
    return {
      page: 1,
      total: 0,
      limit: 10,
      dataList: [],
      skuInfo: {},
      show: false
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    getList(pages = 1) {
      this.page = pages
      // 发送请求获取列表数据
      this.$API.sku.reqList(this.page, this.limit).then(res => {
        if (res.code === 200) {
          this.dataList = res.data.records
          this.total = res.data.total
        }
      })
    },
    handleSizeChange(e) {
      this.limit = e
      this.getList()
    },
    // 上架,下架
    sale(row) {
      this.$API.sku.reqOnSale(row.id).then(res => {
        if (res.code === 200) {
          row.isSale = 1
          this.$message.success('上架成功')
        }
      })
    },
    cancel(row) {
      this.$API.sku.reqCancelSale(row.id).then(res => {
        if (res.code === 200) {
          row.isSale = 0
          this.$message.success('下架成功')
        }
      })
    },
    edit() {
      this.$message('正在开发中')
    },
    getSkuInfo(row) {
      // 展示抽屉
      this.show = true
      this.$API.sku.reqGetSkuById(row.id).then(res => {
        if (res.code === 200) {
          this.skuInfo = res.data
        }
      })
    }
  }
}
</script>

<style scoped>
.el-row .el-col-5 {
  font-size: 18px;
  text-align: right;
}
.el-col {
  margin: 10px 10px;
}
>>> .el-carousel__button {
  width: 10px;
  height: 10px;
  background: red;
  border-radius: 50%;
}
</style>

<style>
.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 150px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
</style>
